package com.my.toolkit.mock;

import java.lang.reflect.Method;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

abstract public class MockCallback implements MethodInterceptor{

	@Override
	public Object intercept(Object target,Method method,Object[] args,MethodProxy methodProxy) throws Throwable{
		if(!interceptor(method)){
			return methodProxy.invokeSuper(target,args);
		}
		if(method.getDeclaringClass()==Object.class){
			return false;
		}
		return this.invoke(method,args);
	}

	//具体执行
	abstract protected Object invoke(Method method,Object[] args);

	//是否拦截某个方法
	abstract protected boolean interceptor(Method method);

}
